<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/2/9
 * Time: 12:28
 */
$arr = [
	"C"      => "I am the GOD",
	"PHP"    => "PHP is the best language int the world",
	"Python" => "Life is short, I use Python",
	"Java"   => "Write once, run anywhere",
	"Go"     => "better C",
];

/**
 * Array
 * (
 * [0] => Array
 * (
 * [0] => I am the GOD
 * [1] => PHP is the best language int the world
 * )
 * [1] => Array
 * (
 * [0] => Life is short, I use Python
 * [1] => Write once, run anywhere
 * )
 * [2] => Array
 * (
 * [0] => better C
 * )
 * )
 */
$chunk = array_chunk( $arr, 2, false );
print_r( $chunk );

/**
 * Array
 * (
 * [0] => Array
 * (
 * [C] => I am the GOD
 * [PHP] => PHP is the best language int the world
 * )
 * [1] => Array
 * (
 * [Python] => Life is short, I use Python
 * [Java] => Write once, run anywhere
 * )
 * [2] => Array
 * (
 * [Go] => better C
 * )
 * )
 */
$chunk = array_chunk( $arr, 2, true );
print_r( $chunk );

//类似分页
function partition( $list, $p/*页数*/ ) {
	$listlen   = count( $list );
	$partlen   = floor( $listlen / $p );
	$partrem   = $listlen % $p;
	$partition = array();
	$mark      = 0;
	for ( $px = 0; $px < $p; $px ++ ) {
		$incr             = ( $px < $partrem ) ? $partlen + 1 : $partlen;
		$partition[ $px ] = array_slice( $list, $mark, $incr );
		$mark             += $incr;
	}

	return $partition;
}

print_r( partition( $arr, 2 ) ); //0 =>[c,php,Python],1 => [Java,Go]
